<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/valueWdatePicker.js"></script
<div class="panel" style="height: 580px; overflow: auto;">
	<div class="panel-body pan" style="height: 580px; overflow: auto;">
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">专题名称 <span class='require'>*</span>
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="name" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			
			
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">分类名称</label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="categorySidName" type="text" placeholder="请选择..."  class="form-control" disabled="true"  />
						<span class="input-group-btn">
							<button  onclick="showCategorySid()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">请选择..</button>
							<button  onclick="deleteCategorySid()" type="button" data-toggle="dropdown" class="btn btn-sm btn-primary">清空</button>
						</span>		
						<input id="categorySid" type="hidden" value="" class="form-control" />
					</div>
				</div>
			</div>
		</div>
		<div style="width:400px;margin-right: auto; padding-bottom: 10px;">
				<label for="inputUsername" class="col-md-3 control-label">
				  <div align="right">父节点
					<span class='require' id="fuji"></span></div>
                </label>
				<div class="col-md-7">
					<div class="input-group input-group-sm mbs" >
						 <input id="parentclassname" type="text"  value="根目录" class="form-control" disabled="true" /> 
						 <input id="parentClassid" type="hidden" value="0" class="form-control" />
						<span class="input-group-btn"><button id="xuanze" onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择类..</button></span>
					</div>
				</div>
			</div>
		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">专题描述
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="description" rows="2" cols="20" class="form-control"></textarea>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">计量类型
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="chargeType" class="form-control">
							<option value="">--请选择--</option>
							<option value="0">按产品库计费</option>
							<option value="1">固定单价计费</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">产品价格
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="price" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">优惠/折扣后金额
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="preferential" type="text" class="form-control" value="" placeholder="输入格式0.00" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">计量单位
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="units" class="form-control">
							<option value="">--请选择--</option>
							<option value="pian">篇</option>
							<!-- <option value="ye">页</option>
							<option value="zi">字</option> -->
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">优惠起始时间
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="preferentialDateStart" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">优惠终止时间
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="preferentialDateEnd" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">封面图片</label>
				<div class="col-md-9">
					<div>
						<div style="display:inline " id="single"></div>
						<input type="button" class="btn btn-primary" style="width: 70px;height: 30px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;" onclick="upImages()" value="上传图片"  />
						<textarea id="uploadImage" name="uploadImage"></textarea>
						<input id="coverImg" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<!-- <div class="col-lg-6"
				style="width: 400px; float:left; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">是否根据知识库同步更新产品数据
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="isSynchronous" class="form-control">
							<option value="0">不同步</option>
							<option value="1">同步</option>
						</select>
					</div>
				</div>
			</div> -->
		</div>
		<div class="row" style="margin-bottom: 10px;">
		<!-- 	<div class="col-lg-6"
				style="width: 400px; float:right; margin-right:20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">web页面链接地址
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="webUrl" type="text" class="form-control" value="" />
					</div>
				</div>
			</div> -->
		</div>
		
		<!-- <div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">solr索引库URL
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="solrCoreUrl" rows="2" cols="20" class="form-control"></textarea>
				</div>
			</div>
		</div> -->

		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">知识库
			</label>
			<div id="classesName" class="row" style="margin-bottom: 10px;">

			</div>
		</div>
		
		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">产品搜索表达式（用户输入）
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="searchExpression" rows="2" cols="20"
						class="form-control"></textarea>
				</div>
			</div>
		</div>
		
		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">产品搜索表达式（系统追加）
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="searchExpressionAdditional" rows="2" cols="20"
						class="form-control" disabled="disabled"></textarea>
				</div>
			</div>
		</div>
		
	</div>
</div>

<?} ?>
<script>
	var roupId = window.parent.getztreeId();
	var roupname = window.parent.getztreename();
	if(roupname !=null){
		$("#parentclassname").val(roupname);
		$("#parentClassid").val(roupId);
	}
	var index1 = window.parent.getlay();
	var _editor;
	var classesIds = "";
	$(function() {
		if (index1 != 0) {
			$.ajax({
				type : "post",
				url : "./repositoryProductUpdate.do",
				data : {
					"id" : index1,
				},
				dataType : "json",
				async : false,
				success : function(data) {
					$("#name").val(data[0].name);
					$("#description").val(data[0].description);
					$("#price").val(data[0].price.toFixed(2));
					$("#units").val(data[0].units);
					$("#status").val(data[0].status);
					$("#webUrl").val(data[0].webUrl);
					$("#classesIds").val(data[0].classesIds);
					$("#parentClassid").val(data[0].pid);
					classesIds = data[0].classesIds;
					$("#searchExpression").val(data[0].searchExpression);
					$("#searchExpressionAdditional").val(data[0].searchExpressionAdditional);
				//	$("#isSynchronous").val(data[0].isSynchronous);
					$("#solrCoreUrl").val(data[0].solrCoreUrl);
					$("#coverImg").val(data[0].coverImg);
					$("#preferential").val(data[0].preferentialPrice.toFixed(2));
					$("#preferentialDateStart").val(data[0].preferentialDateStart);
					$("#preferentialDateEnd").val(data[0].preferentialDateEnd);
					$("#chargeType").val(data[0].chargeType);
					$("#single").html("<img src='"+data[0].coverImg+"' width='30' height='30'/>");
					//selected("classesIds",data[0].classesIds);
					if(data[0].chargeType == '1'){
						document.getElementById('price').disabled = true;
				    	document.getElementById('preferential').disabled = true;
				    	document.getElementById('units').disabled = true;
				    	document.getElementById('preferentialDateStart').disabled = true;
				    	document.getElementById('preferentialDateEnd').disabled = true;
					}
					if(data[0].categorySid != null && data[0].categorySid !=''){
						var categorySids = data[0].categorySid.split('∷');
						$("#categorySid").val(categorySids[0]);
						$("#categorySidName").val(categorySids[1]);
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
		$.ajax({
					type : "post",
					url : "./queryclasses.do",
					data : {},
					dataType : "json",
					async : false,
					success : function(data) {
						//alert(JSON.stringify(data));  
						$("#classesName").html("");
						var str = "";
						for ( var i = 0; i < data.length; i++) {
							str += "<div class='col-lg-1' style='width: 260px; float:left; margin-right:-20px;display:inline;'>";

							str += "<div class='col-md-9'>";
							str += "<div class='input-icon'>";
							str += "	<input type='checkbox' id='"+data[i].id+"' name='checkall' value="+data[i].id+" />&nbsp;&nbsp;";
							str +="	<label for='"+data[i].id+"' name='checkall'>"+data[i].nameZh;
							str += "</label></div>";
							str += "</div>";
							str += "</div>";
							//str+="<input type='checkbox' name='checkall' value="+data[i].id+" />"+data[i].nameZh+"";
						}
						$("#classesName").html(str);
						var classesids2 = classesIds.substring(0,
								classesIds.length - 1)
						var ids = classesids2.split(",");
						for ( var j = 0; j < ids.length; j++) {
							$("input[value=" + ids[j] + "]").attr("checked",
									true);
						}

					},
					error : function(data) {
						alert("请求失败");
					}
				});
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#single").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
	
	
	//选择父类
	function saveclassZTree() {
		parent.layer.open({
			type : 2,
			area : [ '400px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择节点",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["application-special-manage-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	function save() {
	 if ($.trim($("#name").val()).length < 1) {
			alert('专题名不能为空！');
			return null;
		}
		var value = [];
		$("input[name='checkall']:checked").each(function() {
			value.push($(this).val());
		});
		$.ajax({
			type : "post",
			url : "./Addproduct.do",
			data : {
				"id" : index1,
				"name" : $("#name").val(),
				"description" : $("#description").val(),
				"price" : $("#price").val(),
				"units" : $("#units").val(),
				"webUrl" : $("#webUrl").val(),
				"pid":$("#parentClassid").val(),
				"classesIds" : value,
				"searchExpression" : $("#searchExpression").val(),
				"searchExpressionAdditional" : $("#searchExpressionAdditional").val(),
				"isSynchronous" : 0,
				"solrCoreUrl" : $("#solrCoreUrl").val(),
				"coverImg" : $("#coverImg").val(),
				"status" : $("#status").val(),
				"preferential" : $("#preferential").val(),
				"chargeType" : $("#chargeType").val(),
				"preferentialDateStart" : $("#preferentialDateStart").val(),
				"preferentialDateEnd" : $("#preferentialDateEnd").val(),
				"categorySid" : $("#categorySid").val(),

			},
			dataType : "json",
			traditional : true,
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				 window.parent.initTree();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	//   默认单选函数
	function selected(selectname, selectid) {
		$("#" + selectname + " option").each(function() { //遍历全部option
			var v = $(this).val(); //获取option的内容
			if (v == selectid) {
				$(this).attr("selected", "selected");
			}
		});
	}
	//计费类型
	$(document).ready(function () { 
		  $("#chargeType").bind("change",function(){ 
		    if($(this).val()==1){
		    	document.getElementById('price').disabled = true;
		    	document.getElementById('preferential').disabled = true;
		    	$("#preferential").val("0.00");
		    	$("#price").val("");
		    	document.getElementById('units').disabled = true;
		    	document.getElementById('preferentialDateStart').disabled = true;
		    	document.getElementById('preferentialDateEnd').disabled = true;
		    }else{
		    	document.getElementById('price').disabled = false;
		    	document.getElementById('preferential').disabled = false;
		    	$("#preferential").val("");
		    	$("#price").val("");
		    	document.getElementById('units').disabled = false;
		    	document.getElementById('preferentialDateStart').disabled = false;
		    	document.getElementById('preferentialDateEnd').disabled = false;
		    } 
		  }); 
		});
	
	function showCategorySid() {
		parent.layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"选择字典",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["application-repository-product-category.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	function deleteCategorySid(){
		$("#categorySid").val("");
		$("#categorySidName").val("");
	}
</script>